//unity4都是用lambert

Shader "Custom/07ToonShading" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_RampTex("RampTex",2D)="white"{}
		// _Color("Color",Color)=(1,1,1,1)
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200

		CGPROGRAM
		#pragma surface surf Toon //自己写的，不是用系统的

		struct Input {
			float2 uv_MainTex;
		};

		sampler2D _MainTex;     
		sampler2D _RampTex;     

		void surf (Input IN, inout SurfaceOutput o) {
			o.Albedo = tex2D (_MainTex, IN.uv_MainTex);
		}
//自己写的光照模型
		half4 LightingToon(SurfaceOutput s, half3 lightDir, half atten)
		{
			half f= max(dot(s.Normal, lightDir), 0.0); // 平滑过度的光照强度值
           f=  tex2D(_RampTex, fixed2(f,0.5)).r; // 从ramp纹理中获取颜色值
			half4 c;
			c.rgb = s.Albedo * _LightColor0.rgb * (tex2D(_RampTex, fixed2(f,0.5)).rgb);
			c.rgb = f; // 直接使用ramp纹理的颜色值，变成黑白灰
			c.a = s.Alpha;
			return c;
		}
		ENDCG
	}
}

//ramp斜坡纹理